package day21.colllection;

import java.util.*;

/**
 * 学生类，用于演示集合的增删改查操作
 */
public class Student {
    private int id;
    private String name;
    private int age;
    private String major;

    /**
     * 无参构造方法
     */
    public Student() {
    }

    /**
     * 有参构造方法
     * @param id 学号
     * @param name 姓名
     * @param age 年龄
     * @param major 专业
     */
    public Student(int id, String name, int age, String major) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.major = major;
    }

    // getter和setter方法
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    @Override
    public String toString() {
        return "学生" +"学号=" + id +", 名字=" + name +", 年龄=" + age +", 专业=" + major;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return id == student.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}